<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新经资讯后台管理</title>
    <link rel="stylesheet" type="text/css" href="../../static/admin/css/reset.css">
    <link rel="stylesheet" type="text/css" href="../../static/admin/css/main.css">
    <link rel="stylesheet" href="../../static/admin/css/jquery.pagination.css">
    <script type="text/javascript" src="../../static/admin/js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript" src="../../static/admin/js/jquery.pagination.min.js"></script>
</head>
<body>
    <div class="breadcrub">
            当前位置：用户管理>用户列表
        </div>
        <div class="pannel">
            <table class="common_table">
                <tr>
                    <th width="6%">id</th>
                    <th width="18%">用户名</th>
                    <th width="18%">电话</th>
                    <th width="20%">注册时间</th>
                    <th width="20%">上次登录时间</th>
                    <th width="8%">管理操作</th>
                </tr>
                {% for user in data.users %}
                    <tr>
                        <td>{{ user.id }}</td>
                        <td>{{ user.nick_name }}</td>
                        <td>{{ user.mobile }}</td>
                        <td>{{ user.register }}</td>
                        <td>{{ user.last_login }}</td>
                        <td>
                            <a href="javascript:;" class="delete">删除</a>
                        </td>
                    </tr>
                {% endfor %}
            </table>
        </div>

        <div class="box">
            <div id="pagination" class="page"></div>
        </div>

        <script>
            $(function() {
                $("#pagination").pagination({
                    currentPage: {{ data.current_page }},
                    totalPage: {{ data.total_page }},
                    callback: function(current) {
                        window.location.href = '/admin/user_list?p=' + current
                    }
                });

            });
            $('.delete').click(function () {
                //获取删除用户id
                var user_id = $(this).parent().siblings(0).html();
                var params = {"user_id": user_id}
                $.ajax({
                    url: "/admin/delete_user",
                    method: "post",
                    headers: {"X-CSRFToken": getCookie("csrf_token")},
                    data: JSON.stringify(params),
                    contentType: "application/json",
                    success: function (resp) {
                        if (resp.errno == "0") {
                            // 刷新当前界面
                            location.reload();
                        }else {
                            alert(resp.errmsg)
                        }
                    }
                })
            })
            function getCookie(name) {
                var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
                return r ? r[1] : undefined;
            }
        </script>
</body>
</html>